package com.salesforce.samples.templateapp;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;


public class TitleActivity extends FragmentActivity implements GlobalListener{
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.master_details_page_activity);
	}

	public void onCategoryClicked(int position) {
		


		if(position >= 0){                
			AccountsdetailsFragment newFragment = new AccountsdetailsFragment();
			Bundle args = new Bundle();
			args.putInt("Position", position);
			newFragment.setArguments(args);
			FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
			transaction.replace(R.id.viewer, newFragment);
			transaction.commit();
		}
		if(position == -1){

			AccountsdetailsFragment newFragment = new AccountsdetailsFragment();
			Bundle args = new Bundle();
			args.putInt("Position", -1);
			newFragment.setArguments(args);
			FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
			transaction.replace(R.id.viewer, newFragment);
			transaction.commit();

		}if(position == -2)
		{
			finish();
		}

	}

	@Override
	public void onNewContact(String[] args) {
		
		ContactDetailsFragment newFragment = new ContactDetailsFragment();
		Bundle args2 = new Bundle();
		args2.putInt("Position", 0);
		args2.putString("MailingCountry", args[0]);
		args2.putString("MaillingCity", args[1]);
		args2.putString("Maillingstate", args[2]);
		args2.putString("MaillingStreet", args[3]);
		args2.putString("MaillingZip", args[4]);
		args2.putString("Contactphone", args[5]);
		args2.putString("ContactAccountName", args[6]);
		args2.putString("AccountId", args[7]);
		newFragment.setArguments(args2);
		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
		transaction.replace(R.id.viewer, newFragment);
		transaction.commit();
	}

	@Override
	public void onGetContacts(String[] args) {
	
		ContactDetailsFragment newFragment = new ContactDetailsFragment();
		Bundle args2 = new Bundle();
		args2.putString("LastName", args[0]);
		args2.putString("FirstName", args[1]);
		args2.putString("Phone", args[2]);
		args2.putString("MailingCity", args[3]);
		args2.putString("MailingCountry", args[4]);
		args2.putString("MailingPostalCode", args[5]);
		args2.putString("MailingState", args[6]);
		args2.putString("MaillingStreet", args[7]);
		args2.putString("OtherCity", args[8]);
		args2.putString("OtherCountry", args[9]);
		args2.putString("OtherPostalCode", args[10]);
		args2.putString("OtherState", args[11]);
		args2.putString("OtherStreet", args[12]);
		args2.putString("Email", args[13]);
		args2.putString("MobilePhone", args[14]);
		args2.putString("Title", args[15]);
		args2.putString("AccountId", args[16]);
		args2.putInt("Position", 1);
		
		newFragment.setArguments(args2);
		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
		transaction.replace(R.id.viewer, newFragment);
		transaction.commit();
		
	}


}
